// ============================================================================
//
// LCP-net framework by Pierre CHATEL chatelp@gmail.com
// Distributed under GPLv3
// Copyright (C) THALES Land & Joint Systems, 2008, 2009. All rights reserved
//
// ============================================================================

/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.thalesgroup.preferenceFramework.models.impl;


import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;
import com.thalesgroup.preferenceFramework.models.Arc;
import com.thalesgroup.preferenceFramework.models.ModelsPackage;
import com.thalesgroup.preferenceFramework.models.Node;
import com.thalesgroup.preferenceFramework.models.PreferenceNetwork;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Arc</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.impl.ArcImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.impl.ArcImpl#getStartNode <em>Start Node</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.impl.ArcImpl#getEndNode <em>End Node</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.impl.ArcImpl#getPreferenceNetwork <em>Preference Network</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ArcImpl extends EObjectImpl implements Arc {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getStartNode() <em>Start Node</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartNode()
	 * @generated
	 * @ordered
	 */
	protected Node startNode;

	/**
	 * The cached value of the '{@link #getEndNode() <em>End Node</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndNode()
	 * @generated
	 * @ordered
	 */
	protected Node endNode;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ArcImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModelsPackage.Literals.ARC;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getStartNode() {
		if (startNode != null && startNode.eIsProxy()) {
			InternalEObject oldStartNode = (InternalEObject)startNode;
			startNode = (Node)eResolveProxy(oldStartNode);
			if (startNode != oldStartNode) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelsPackage.ARC__START_NODE, oldStartNode, startNode));
			}
		}
		return startNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetStartNode() {
		return startNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetStartNode(Node newStartNode, NotificationChain msgs) {
		Node oldStartNode = startNode;
		startNode = newStartNode;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__START_NODE, oldStartNode, newStartNode);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartNode(Node newStartNode) {
		if (newStartNode != startNode) {
			NotificationChain msgs = null;
			if (startNode != null)
				msgs = ((InternalEObject)startNode).eInverseRemove(this, ModelsPackage.NODE__OUT_ARCS, Node.class, msgs);
			if (newStartNode != null)
				msgs = ((InternalEObject)newStartNode).eInverseAdd(this, ModelsPackage.NODE__OUT_ARCS, Node.class, msgs);
			msgs = basicSetStartNode(newStartNode, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__START_NODE, newStartNode, newStartNode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getEndNode() {
		if (endNode != null && endNode.eIsProxy()) {
			InternalEObject oldEndNode = (InternalEObject)endNode;
			endNode = (Node)eResolveProxy(oldEndNode);
			if (endNode != oldEndNode) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelsPackage.ARC__END_NODE, oldEndNode, endNode));
			}
		}
		return endNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetEndNode() {
		return endNode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEndNode(Node newEndNode, NotificationChain msgs) {
		Node oldEndNode = endNode;
		endNode = newEndNode;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__END_NODE, oldEndNode, newEndNode);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndNode(Node newEndNode) {
		if (newEndNode != endNode) {
			NotificationChain msgs = null;
			if (endNode != null)
				msgs = ((InternalEObject)endNode).eInverseRemove(this, ModelsPackage.NODE__IN_ARCS, Node.class, msgs);
			if (newEndNode != null)
				msgs = ((InternalEObject)newEndNode).eInverseAdd(this, ModelsPackage.NODE__IN_ARCS, Node.class, msgs);
			msgs = basicSetEndNode(newEndNode, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__END_NODE, newEndNode, newEndNode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PreferenceNetwork getPreferenceNetwork() {
		if (eContainerFeatureID != ModelsPackage.ARC__PREFERENCE_NETWORK) return null;
		return (PreferenceNetwork)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetPreferenceNetwork(PreferenceNetwork newPreferenceNetwork, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newPreferenceNetwork, ModelsPackage.ARC__PREFERENCE_NETWORK, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPreferenceNetwork(PreferenceNetwork newPreferenceNetwork) {
		if (newPreferenceNetwork != eInternalContainer() || (eContainerFeatureID != ModelsPackage.ARC__PREFERENCE_NETWORK && newPreferenceNetwork != null)) {
			if (EcoreUtil.isAncestor(this, newPreferenceNetwork))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newPreferenceNetwork != null)
				msgs = ((InternalEObject)newPreferenceNetwork).eInverseAdd(this, ModelsPackage.PREFERENCE_NETWORK__ARCS, PreferenceNetwork.class, msgs);
			msgs = basicSetPreferenceNetwork(newPreferenceNetwork, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelsPackage.ARC__PREFERENCE_NETWORK, newPreferenceNetwork, newPreferenceNetwork));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelsPackage.ARC__START_NODE:
				if (startNode != null)
					msgs = ((InternalEObject)startNode).eInverseRemove(this, ModelsPackage.NODE__OUT_ARCS, Node.class, msgs);
				return basicSetStartNode((Node)otherEnd, msgs);
			case ModelsPackage.ARC__END_NODE:
				if (endNode != null)
					msgs = ((InternalEObject)endNode).eInverseRemove(this, ModelsPackage.NODE__IN_ARCS, Node.class, msgs);
				return basicSetEndNode((Node)otherEnd, msgs);
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetPreferenceNetwork((PreferenceNetwork)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelsPackage.ARC__START_NODE:
				return basicSetStartNode(null, msgs);
			case ModelsPackage.ARC__END_NODE:
				return basicSetEndNode(null, msgs);
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				return basicSetPreferenceNetwork(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				return eInternalContainer().eInverseRemove(this, ModelsPackage.PREFERENCE_NETWORK__ARCS, PreferenceNetwork.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModelsPackage.ARC__NAME:
				return getName();
			case ModelsPackage.ARC__START_NODE:
				if (resolve) return getStartNode();
				return basicGetStartNode();
			case ModelsPackage.ARC__END_NODE:
				if (resolve) return getEndNode();
				return basicGetEndNode();
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				return getPreferenceNetwork();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModelsPackage.ARC__NAME:
				setName((String)newValue);
				return;
			case ModelsPackage.ARC__START_NODE:
				setStartNode((Node)newValue);
				return;
			case ModelsPackage.ARC__END_NODE:
				setEndNode((Node)newValue);
				return;
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				setPreferenceNetwork((PreferenceNetwork)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModelsPackage.ARC__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ModelsPackage.ARC__START_NODE:
				setStartNode((Node)null);
				return;
			case ModelsPackage.ARC__END_NODE:
				setEndNode((Node)null);
				return;
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				setPreferenceNetwork((PreferenceNetwork)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModelsPackage.ARC__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ModelsPackage.ARC__START_NODE:
				return startNode != null;
			case ModelsPackage.ARC__END_NODE:
				return endNode != null;
			case ModelsPackage.ARC__PREFERENCE_NETWORK:
				return getPreferenceNetwork() != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //ArcImpl
